import wepy from 'wepy';
import tip from '@/utils/tip';
import {
  URL
} from '../pages/config';

const _upload = async () => {
  // 选择图片
  let result = await wepy.chooseImage({
    count: 1,
    sizeType: ['original'],
    sourceType: ['album', 'camera'],
  })
  // 上传图片
  if(result) {
    let res = await wepy.uploadFile({
      url: URL + 'app/aliossUpload',
      header: {
        "Content-Type": "multipart/form-data"
      },
      filePath: result.tempFilePaths[0],
      name: 'file'
    })
    if(res.statusCode) {
      return JSON.parse(res.data).url
    }else {
      tip.error('上次失败!')
    }
  }
}

module.exports =  {
  _upload
}
